package com.example.kafkademo.producer;

import io.vertx.core.Vertx;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.kafka.client.consumer.KafkaConsumer;
import io.vertx.kafka.client.producer.KafkaProducer;
import io.vertx.kafka.client.producer.KafkaProducerRecord;
import io.vertx.kafka.client.serialization.JsonObjectSerializer;
import org.apache.kafka.common.serialization.LongSerializer;

import java.util.Properties;

public class VppcProducer {

    public static void main(String[] args) {
        Vertx vertx=Vertx.vertx();
        final Properties props = new Properties();
        props.put("bootstrap.servers", "192.168.1.129:9092");
        props.put("key.serializer", LongSerializer.class.getName());
        props.put("value.serializer", JsonObjectSerializer.class.getName());

        KafkaProducer<Long, JsonObject> producer=KafkaProducer.createShared(vertx, "vppcProducer", props);

//        JsonObject message=new JsonObject()
//                .put("templateName","demo.peb")
//                .put("pdfName","kafka整合Pebble和iTextCos.pdf")
//                .put("name","贺兴杰");
//        producer.write(KafkaProducerRecord.create("vppc",message), ar -> {
//            if (ar.succeeded()) {
//                System.out.println("消息发送成功");
//            } else {
//                System.out.println("消息发送失败");
//            }
//            vertx.close();
//        });

        //这里的id和key都必须一致，并且和qjnext.corporation的id字段一致
        JsonObject message=new JsonObject()
                .put("id",31621293415596033L)
                .put("title","南京巨龙信息技术有限公司")
                .put("address","淞沪路1号1层101室")
                .put("zipcode","123456")
                .put("district_id",73)
                .put("keycloak_node_id",1)
                .put("fullname","张三")
                .put("mobile","12341234000")
                .put("password","123456")
                .put("enabled",true);
        producer.write(KafkaProducerRecord.create("open-business", 31621293415596033L, message));


//        JsonObject data=new JsonObject()
//                .put("type","node")
//                .put("action","create")
//                .put("auth_server_url","http://192.168.1.129:8282/auth")
//                .put("username","admin")
//                .put("password","123456")
//                .put("keycloak_node_id",1)
//                .put("enabled","true");
//        producer.write(KafkaProducerRecord.create("keycloak", 10001L, data));


        //发送sms-send的消息
//        producer.write(KafkaProducerRecord.create("sms", 100L, new JsonObject()
//                .put("mobile", "13728389012")
//                .put("template_name", "activated-employee")
//                .put("arguments", new JsonArray())));


        //发送消息到api-gateway的主题
//        producer.write(KafkaProducerRecord.create("api-gateway", 9999L, new JsonObject()
//                .put("type", "blah")));
//        producer.write(KafkaProducerRecord.create("api-gateway", 9999L, new JsonObject()
//                .put("type", "realm")));
//        producer.write(KafkaProducerRecord.create("api-gateway", 9999L, new JsonObject()
//                .put("type", "realm")
//                .put("auth-server-url","http://192.168.1.129:8282/auth")
//                .put("secret", "e26c0a8a-4955-4d26-a820-4f11f7ed3eb3")));
    }
}
